package Test1;


import java.util.ArrayList;
import java.util.PriorityQueue;

class ListNode {
    int val;
    ListNode next = null;
    public ListNode(int val) {
      this.val = val;
   }
}


public class TestDemo5 {
    public int minNumberInRotateArray(int [] array) {
        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>(array.length,(a,b)->(a-b));
        for (int i = 0; i < array.length; i++) {
            priorityQueue.add(array[i]);
        }
        return priorityQueue.poll();
    }
    public static void main(String[] args) {

    }
    public ListNode mergeKLists (ArrayList<ListNode> lists) {
        if(lists.size() == 0) return null;
        PriorityQueue<ListNode> queue = new PriorityQueue<>(lists.size(),(a,b)->{return a.val- b.val;});
        ListNode newHead = new ListNode(-1);
        ListNode p = newHead;
        for(ListNode head : lists) {
            if(head != null) {
                queue.add(head);
            }
        }
        while (queue.size() != 0) {
            ListNode node = queue.poll();
            p.next = node;
            //取一个放一个
            if(node.next != null) {
                queue.add(node.next);
            }
            p = p.next;
        }
        return newHead.next;
    }
}
